package controller.util;

import constant.Constant;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class InterceptorController implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        Object obj = request.getSession().getAttribute(Constant.SESSION_USER);
        System.out.println(obj);
        if (null == obj) {
            String contextPath = request.getContextPath();
            String path = contextPath+"/WEB-INF/front/front_index.jsp";
            System.out.println(path);
            request.getRequestDispatcher(path).forward(request,response);
            return false;
        }
        return true;
    }
}
